#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
int main()
{
  pid_t id = fork();
  if(id == 0){
    printf("begin exec----------------------\n");
    //sleep(2);
    
    char * const argv[] = {"ps", "-ef", NULL};
    char *const envp[] = {"PATH=/bin:/usr/bin", "TERM=console", NULL};
  
    //execl("bin/ps", "ps", "-ef", NULL);
    
    // execl 1:path 2:commd 3:NULL,end of commd
    //execl("/usr/bin/ls", "ls", "-a", "-i", "-l", NULL);
    // 任务管理器
    //execl("/usr/bin/top","top", NULL);
    //execl("/usr/bin/ps","ps","-e","-l","-f",NULL);
    //execl("/usr/bin/ls","ls","-al",NULL);
    
    // 有p的，可以使用环境变量，无需自己写路径
    //execlp("ls","ls","-i","-l","-a",NULL);

    //带e的，自己组装，维护环境变量envp
    //execle("ps", "ps", "-ef", NULL, envp);
    //
    //带v的
    //execv("bin/ps", argv);
  
  //  char *arg[]={
  //    "ls",
  //    "-a",
  //    "-l",
  //    "-i",
  //    NULL
  //  };
    
    // 带v的 参数写进数组中
    // execv("usr/bin/ls",arg);
    // execvp("ls",arg);
    //exit(101);
  }
//  int status = 0;
//  pid_t ret = waitpid(id, &status, 0);
//  if(ret > 0){
//    printf("signal : %d\n",status & 0x7F);
//    printf("exit code : %d\n", (status>>8) & 0xFF );
//  }
  
  // printf("after ----------------------\n");
  return 0;
}
